<template>
	<view class="pics">
		<scroll-view  scroll-y class="scroll-left">
			<view class="scroll-item" v-for="(item,index) in scroll" :key="item.id" @click="leftItemClick(item.id, index)"
			:class = "active === index?'active':''">
				{{item.title}}
			</view>
		</scroll-view>
		<scroll-view scroll-y="true" class="scroll-right">
			<view v-for="item in detailData" class="item">
				<image src="../../static/pics/mv.jpg" mode="" @click="previewImage()"></image>
				<text>{{item.title}}</text>
			</view>
			<text v-if="detailData.length === 0">暂无数据</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scroll:[],
				detailData:[],
				active:0
			}
		},
		methods: {
			async getPictureCate(){
				let res = await this.$myRequest({
					url:"/api/getimgcategory"
				})
				this.scroll = res.data.message
				
			},
			async leftItemClick(id,index){
				this.active = index
				let res = await this.$myRequest({
					url:"/api/getimages/"+id
				})
				this.detailData = res.data.message
			},
			previewImage(){
				let urls = this.detailData.map(item=>{
					//服务器图片错误，以下句子是把服务器的地址图片换成本地的地址图片
					item.img_url = "../../static/pics/mv.jpg"
					return item.img_url
				})
				uni.previewImage({			
					urls
				})
			}
		},
		onLoad() {
			this.getPictureCate()
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		width: 100%;
		background:#e6e6e6;
		.pics{
			height: 100%;
			display: flex;
			.scroll-left{
				width: 210rpx;
				height: 100%;
				.scroll-item{
					width: 100%;
					height: 120rpx;
					border-bottom:1rpx solid #eee;
					background-color: #fff;
					font-size: 30rpx;
					line-height: 120rpx;
					text-align: center;
				}
				.active{
					background: #b50e03;
					color: #fff;
				}
			}
			.scroll-right{
				width: 540rpx;
				height: 100%;
				box-sizing: border-box;
				margin: 0 8rpx;
				.item{
					image{
						display: block;
						width:100%;
						height: 520rpx;
						border-radius: 5px;
						margin: 20rpx 0 0 0;
					}
					text{
						display:block;
						width: 100%;
						font-size: 30rpx;
						line-height: 60rpx;
						background: #fff;
					}
				}				
			}
		}
		
	}
</style>
